<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function cleartbox()
{	
	document.getElementById("Sea_Sch").innerHTML="";
}
</script>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","sch_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.form1.SchName.value=val;
document.getElementById("List").innerHTML="";
var xmlhttp;    
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("labid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getLabId.php?q="+val,true);
xmlhttp.send();
}
</script>
<link rel="stylesheet" href="../css/datepicker.css" type="text/css" />
    <link rel="stylesheet" media="screen" type="text/css" href="../css/layout.css" />
  	<script type="text/javascript" src="../js/jquery.js"></script>
	<script type="text/javascript" src="../js/datepicker.js"></script>
    <script type="text/javascript" src="../js/eye.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/layout.js?ver=1.0.2"></script>
</head>
<body>
<?php
include_once ("../Login/databaseconnection.php");
if(!loggedin())
{
require_once ("../index.php");
}
else
{
	date_default_timezone_set("Europe/Paris");
    $t_d=date("Y-m-d");
if(isset($_POST['Register']))
	   { 
$New_Resource=$_POST['New_Resource'];
$Serial_Number=$_POST['Serial_Number'];
$Resource_Id=$_POST['Resource_Id'];
$Lab_Id=$_POST['Lab_Id'];
 $Functioning=$_POST['Functioning'];
    $Brand_Name=$_POST['Brand_Name'];
    $Date_Of_Supplied=$_POST['Date_Of_Supplied'];
    $Name_Of_Supplier=$_POST['Name_Of_Supplier'];
    $Funding_Source=$_POST['Funding_Source'];
	$SchName=$_POST['SchName'];
	$name=explode(",",$SchName);
    $nam=$name[0];
$tn=count($name);
for($i=1;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$name[$i];
}
else
{
$adr=$adr.",".$name[$i];
}
}
$results= mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($results))
{
 $School_Id=$row['School_Id'];
}
	if($Serial_Number==""||($Resource_Id=="Select One"&&$New_Resource==""))
	   {
	   $_SESSION['errorin']="Indexed details are required Please fill all!";
	   }
	   if($Serial_Number!=""&&($Resource_Id!="Select One"||$New_Resource!=""))
	   {
$Lab_Che=mysql_query("SELECT * FROM resource_details WHERE Serial_Number='$Serial_Number' AND Resource_Id='$Resource_Id'");
if($Lab_Che)
{
if($rowl=mysql_fetch_array($Lab_Che))
		{
			$_SESSION['errorexi']="Sorry this resource's record already exists";
		}
		
		else
		{
		if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
  $get_lab=mysql_query("SELECT * FROM lab WHERE School_Id='$Own_School_Id'");
  if($rowlab=mysql_fetch_array($get_lab))
{
$Own_Lab_Id=$rowlab['Lab_Id'];
if($Lab_Id==$Own_Lab_Id)
	{
	require_once 'REG.php';
	}
	 else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
}
}
}
		else if($_SESSION['Access_Type']=="Administrator")
{
require_once 'REG.php';
}   
   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
	}
	}
	}
?>
<?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?> 
  <div id="content">
	<div id="main">
	  <div id="bodyfield">
      <div id="lefttablereg">
  <form action="#" method="POST" name="form1">
  <table width="459" height="366" border="0" class="tablefontv">
    <tr>
      <td height="18" colspan="5"  scope="row" class="err"><?php
		if(isset($_POST['Register']))
{
if(isset($_SESSION['errornotallo']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errornotallo'];
unset($_SESSION['errornotallo']);
}
	if(isset($_SESSION['errorin']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['errorexi']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorexi'];
		unset($_SESSION['errorexi']);
	}
	if(isset($_SESSION['error']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'];
		unset($_SESSION['error']);
		
	}
}
		?></td>		    
    </tr>
    <tr>
      <th  scope="row">&nbsp;</th>
      <td height="31"  scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="31"  scope="row">Resource Id:</td>
      <td width="187">
      <select name="Resource_Id" id="select">
          <?php
	  
	  if(isset($_POST['Register']))
	  {
	  $res_typ=mysql_query("SELECT * FROM resource WHERE Resource_Id='".$Resource_Id."'");
	  if($row_typ=mysql_fetch_array($res_typ))
	  {
	  $Res_Type=$row_typ['Resource_Type'];
	  }
	echo '<option value="'.$Resource_Id.'">'.$Res_Type.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
          <?php
	  $res=mysql_query("SELECT DISTINCT(Resource_Id) FROM resource");
	  
  while($row=mysql_fetch_array($res))
  {
	  $Res_Id=$row['Resource_Id'];
	  $res_typ=mysql_query("SELECT * FROM resource WHERE Resource_Id='".$Res_Id."'");
	  if($row_typ=mysql_fetch_array($res_typ))
	  {
	  $Res_Type=$row_typ['Resource_Type'];
	  }
	  if($Res_Id!=$Resource_Id)
{
	 echo '<option value="'.$Res_Id.'">'.$Res_Type.'</option>';
}
	 
  }
	  ?>
        </select><br/><label><font color="red">or</font> New resource:</label>&nbsp;&nbsp;&nbsp;
	  <?php
	  if($New_Resource!="")
	  {
	  echo "<input type='text' name='New_Resource' value='$New_Resource'/>";
	  }
	  else
	  {
	  echo "<input type='text' name='New_Resource'/>";
	  }
	  ?>
      </td>
      <td width="67" rowspan="9" class="err">
	     
	   </td>
    </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td height="31" scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="31" scope="row">School's Name:</td>
      <td><?php
	 	 	if($_SESSION['Access_Type']=="Teacher in Charge")
{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id']; 
    $snam=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
}
	  if(isset($_GET['School_Id']))
{
$School_Id=$_GET['School_Id'];
 $snam=mysql_query("SELECT * FROM school WHERE School_Id='$School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
}
	 echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' onClick='cleartbox()' size='40' readonly='readonly'/>";
}
	else if($_SESSION['Access_Type']=="Administrator")
{
	  if(isset($_GET['School_Id']))
{
$School_Id=$_GET['School_Id'];
 $snam=mysql_query("SELECT * FROM school WHERE School_Id='$School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
	  	 echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' onClick='cleartbox()' size='40' readonly='readonly'/>";
}
else
{
	    echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' onClick='cleartbox()' size='40'/>";
		}
}
	  ?></td>
    </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td height="31" scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="31" scope="row">Lab Id:</td>
       <td><div id="labid"><select name="Lab_Id" id="select">
	  <?php	  
if(isset($_POST['Register'])||isset($_GET['Lab_Id']))
{
if(isset($_GET['Lab_Id']))
{
$Lab_Id=$_GET['Lab_Id'];
}
	echo '<option value="'.$Lab_Id.'">'.$Lab_Id.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	 if($_SESSION['Access_Type']=="Teacher in Charge")
{
$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
  echo $Own_School_Id=$rowsch['School_Id'];
   }
$lab=mysql_query("SELECT DISTINCT(Lab_Id) FROM lab WHERE School_Id='$Own_School_Id'");
  while($row=mysql_fetch_array($lab))
  {
	 $La_Id=$row['Lab_Id'];
	  if($La_Id!=$Lab_Id)
{
	echo '<option value="'.$La_Id.'">'.$La_Id.'</option>';
}
 
  }
	  }
else if($_SESSION['Access_Type']=="Administrator")
{
	  $lab=mysql_query("SELECT DISTINCT(Lab_Id) FROM lab");
  while($row=mysql_fetch_array($lab))
  {
	 $La_Id=$row['Lab_Id'];
		  if($La_Id!=$Lab_Id)
{
	echo '<option value="'.$La_Id.'">'.$La_Id.'</option>';
}
  
  }
}
	 ?>
      </select></div></td>
      </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td height="31" scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="31" scope="row">Serial Number:</td><?php
		if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Serial_Number' value='$Serial_Number'/>";
echo '</td>';
}
else
{
echo '<td>';
echo "<input type='text' name='Serial_Number' value='$Serial_Number'/>";
echo '</td>';
}
?>
      <td>
	  </td>
      </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td height="45" scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="45" scope="row">Functioning: </td><?php
if(isset($_POST['Register']))
{

if($Functioning=="Yes")

{
echo '<td>';echo '<label>';
          echo '<input type="radio" name="Functioning" value="Yes" checked="checked"/>';
		  
          echo 'Yes';
		  echo '</label>';
        echo '<br />';
        echo '<label>';
          echo '<input type="radio" name="Functioning" value="No" />';
          echo 'No';
		  echo '</label>';
		  echo '</td>';
		  }
		  if($Functioning=="No")

{
echo '<td>';echo '<label>';
          echo '<input type="radio" name="Functioning" value="Yes"/>';
		  
          echo 'Yes';
		  echo '</label>';
        echo '<br />';
        echo '<label>';
          echo '<input type="radio" name="Functioning" value="No" checked="checked"/>';
          echo 'No';
		  echo '</label>';
		  echo '</td>';
		  }
		 if($Functioning=="")
{
echo '<td>';echo '<label>';
          echo '<input type="radio" name="Functioning" value="Yes"/>';
		  
          echo 'Yes';
		  echo '</label>';
        echo '<br />';
        echo '<label>';
          echo '<input type="radio" name="Functioning" value="No" />';
          echo 'No';
		  echo '</label>';
		  echo '</td>';
		  }
}
if(!isset($_POST['Register']))
{
echo '<td>';echo '<label>';
          echo '<input type="radio" name="Functioning" value="Yes"/>';
		  
          echo 'Yes';
		  echo '</label>';
        echo '<br />';
        echo '<label>';
          echo '<input type="radio" name="Functioning" value="No" />';
          echo 'No';
		  echo '</label>';
		  echo '</td>';
		  }
?>
      <td>
	    </td>
      </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td height="31" scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="31" scope="row">Brand Name:</td><?php
if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Brand_Name' value='$Brand_Name'/>";
echo '</td>';
}
else
{
echo '<td>';
echo "<input type='text' name='Brand_Name'/>";
echo '</td>';
}
?>
      <td>
	  </td>
      </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td height="31" scope="row"></td>
      <td height="31" scope="row">Date Of Supplied:</td><?php
		if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Date_Of_Supplied' value='$Date_Of_Supplied' class='inputDate' id='inputDate'>";
echo '</td>';

}
else
{
echo '<td>';

echo "<input type='text' name='Date_Of_Supplied' value='$t_d' class='inputDate' id='inputDate'>";
echo '</td>';

}
?>
      <td>
	  </td>
      </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td height="31" scope="row"></td>
	  <td height="31" scope="row">Name Of Supplier:</td><?php
		if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Name_Of_Supplier' value='$Name_Of_Supplier'/>";
echo '</td>';

}
else
{
echo '<td>';
echo "<input type='text' name='Name_Of_Supplier'/>";
echo '</td>';
}
?>
	  <td> 	 </td>
      </tr>
    <tr>
      <th width="10" scope="row">&nbsp;</th>
      <td width="10" height="31" scope="row"></td>
      <td width="163" scope="row">Funding Source: </td><?php
		if(isset($_POST['Register']))
{

echo '<td>';
echo "<input type='text' name='Funding_Source' value='$Funding_Source'/>";
echo '</td>';

}
else
{

echo '<td>';
echo "<input type='text' name='Funding_Source'/>";
echo '</td>';

}
?>
      <td> 
	 </td>
      </tr>
	  </table>
  <br/>
  <a href="RegRes.php" class="reset">Reset |</a><input name="Register" align="middle" type="submit" value="Register" class="buttonok"/>
 </form>
 </div>
 <div id="righttablereg">
<?php
 if($_SESSION['OK']!="OK")
{
?>
 <div class="suggestionListsch" id="List"></div>
<?php
}
if(isset($_POST['Register']))
{
if($_SESSION['OK']=="OK")
{
if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
  $result=mysql_query("SELECT * FROM resource_details WHERE School_Id='$Own_School_Id' AND Lab_Id='$Lab_Id'");
 
echo '<br/>';
if(mysql_num_rows($result)!=0)
   {
   echo '<div style =" width:540px; overflow-x:scroll;">';
echo '<table width="208" border="1" class="tablefontv" >
<tr bgcolor="#6AB5FF">
<td><font color="#000000">Resource Id</font></td>
<td><font color="#000000">Lab Id</font></td>
<td><font color="#000000">Serial Number</font></td>
<td><font color="#000000">Functioning</font></td>
<td><font color="#000000">Brand Name</font></td>
<td><font color="#000000">Date Of Supplied</font></td>
<td><font color="#000000">Name Of Supplier</font></td>
<td><font color="#000000">Funding_Source</font></td>
<td><font color="#000000">School Id</font></td>
<td><font color="#000000">Last Updated Date</font></td>
</tr>';

  while($row=mysql_fetch_array($result))
  {
  $Resource_Id=$_SESSION['Resource_Id'];
$Serial_Number=$_SESSION['Serial_Number'];

  if($row['Resource_Id']=="$Resource_Id"&&$row['Serial_Number']=="$Serial_Number")
  {
    echo '<tr bgcolor="#936">';
    echo '<td><font color="#000000">'.$row['Resource_Id'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Lab_Id'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Serial_Number'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Functioning'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Brand_Name'].'</font></td>';
	echo '<td><font color="#000000">'.$row['Date_Of_Supplied'].'</font></td>';
	echo '<td><font color="#000000">'.$row['Name_Of_Supplier'].'</font></td>';   
    echo '<td><font color="#000000">'.$row['Funding_Source'].'</td>';
	echo '<td><font color="#000000">'.$row['School_Id'].'</td>';    
	echo '<td><font color="#000000">'.$row['Last_Updated_Date'].'</font></td>';
  echo '</tr>';
  unset($_SESSION['Resource_Id']);
  unset($_SESSION['Serial_Number']);
 
  }
 else
  {
    echo '<tr bgcolor="#CCCCCC">';
    echo '<td>'.$row['Resource_Id'].'</td>';
    echo '<td>'.$row['Lab_Id'].'</td>';
    echo '<td>'.$row['Serial_Number'].'</td>';
    echo '<td>'.$row['Functioning'].'</td>';
    echo '<td>'.$row['Brand_Name'].'</td>';
	echo '<td>'.$row['Date_Of_Supplied'].'</td>';
	 echo '<td>'.$row['Name_Of_Supplier'].'</td>';   
    echo '<td>'.$row['Funding_Source'].'</td>';
	echo '<td>'.$row['School_Id'].'</td>';
	echo '<td>'.$row['Last_Updated_Date'].'</td>';
   echo '</tr>';
  }
  }
   echo "</table>";
   echo '</div>';

  }
  unset($_SESSION['OK']);
  }
}
else if($_SESSION['Access_Type']=="Administrator")
{
$result=mysql_query("SELECT * FROM resource_details");
echo '<br/>';
if(mysql_num_rows($result)!=0)
   {
   echo '<div style =" width:540px; overflow-x:scroll;">';
echo '<table border="1" class="tablefontv" >
<tr bgcolor="#6AB5FF">
<td><font color="#000000">Resource Id</font></td>
<td><font color="#000000">Lab Id</font></td>
<td><font color="#000000">Serial Number</font></td>
<td><font color="#000000">Functioning</font></td>
<td><font color="#000000">Brand Name</font></td>
<td><font color="#000000">Date Of Supplied</font></td>
<td><font color="#000000">Name Of Supplier</font></td>
<td><font color="#000000">Funding_Source</font></td>
<td><font color="#000000">School Id</font></td>
<td><font color="#000000">Last Updated Date</font></td>
</tr>';

  while($row=mysql_fetch_array($result))
  {
  $Resource_Id=$_SESSION['Resource_Id'];
$Serial_Number=$_SESSION['Serial_Number'];

  if($row['Resource_Id']=="$Resource_Id"&&$row['Serial_Number']=="$Serial_Number")
  {
    echo '<tr bgcolor="#936">';
    echo '<td><font color="#000000">'.$row['Resource_Id'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Lab_Id'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Serial_Number'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Functioning'].'</font></td>';
    echo '<td><font color="#000000">'.$row['Brand_Name'].'</font></td>';
	echo '<td><font color="#000000">'.$row['Date_Of_Supplied'].'</font></td>';
	echo '<td><font color="#000000">'.$row['Name_Of_Supplier'].'</font></td>';   
    echo '<td><font color="#000000">'.$row['Funding_Source'].'</td>';
	echo '<td><font color="#000000">'.$row['School_Id'].'</td>';    
	echo '<td><font color="#000000">'.$row['Last_Updated_Date'].'</font></td>';
  echo '</tr>';
  unset($_SESSION['Resource_Id']);
  unset($_SESSION['Serial_Number']);
 
  }
 else
  {
    echo '<tr bgcolor="#CCCCCC">';
    echo '<td>'.$row['Resource_Id'].'</td>';
    echo '<td>'.$row['Lab_Id'].'</td>';
    echo '<td>'.$row['Serial_Number'].'</td>';
    echo '<td>'.$row['Functioning'].'</td>';
    echo '<td>'.$row['Brand_Name'].'</td>';
	echo '<td>'.$row['Date_Of_Supplied'].'</td>';
	 echo '<td>'.$row['Name_Of_Supplier'].'</td>';   
    echo '<td>'.$row['Funding_Source'].'</td>';
	echo '<td>'.$row['School_Id'].'</td>';
	echo '<td>'.$row['Last_Updated_Date'].'</td>';
   echo '</tr>';
  }
  }
   echo "</table>";
echo '</div>';
  }
  unset($_SESSION['OK']);
  }
  }
}
  ?>
 </div>
</div>
</div>
 </div>
<div id="sidebar"><br/>
<div id="partners" class="boxed">
<h2 class="title">RESOURCES</h2>
</div>
<?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
?>

<?php

	}
?>
</body>
</html>